# -*- coding: utf-8 -*-
# @Time    : 2021/4/22 17:36
# @Author  : Zhangrenjie
# @Email   : zhangrenjie1998@163.com
# @File    : sc_img.py
# @Software: PyCharm
import requests
import re

# https://www.sanchuangedu.cn/
# 三创官网
sc_url = 'https://www.sanchuangedu.cn'
request = requests.get('https://www.sanchuangedu.cn/')
# 获取网站源码
text = request.text
# 爬取图片源码
img = re.findall(r'<img.*?src="(.*?)".*?>', text)
n = 0
for i in img:
    # 获取图片后缀
    suffix = str(i).split('.')[1]
    n += 1
    # 判断图片源码是否是完整的地址
    if sc_url not in i:
        url = sc_url + str(i)
    # 获取图片
    request_img = requests.get(url)
    # 保存
    with open(f'img/sc_{n}.{suffix}', 'wb') as f:
        f.write(request_img.content)



